package game;

import engine.loader.Resources;
import engine.render.SoundBuffer;
import engine.scene.Scene3D;
import engine.scene.SoundSource;
import engine.scene.TriGroup;
import math.vector.Vecmath;
import math.vector.vec3f;

public class Level
{
    
    private Scene3D scene;
    //<editor-fold defaultstate="collapsed" desc="getScene">
    public Scene3D getScene()
    {
        return this.scene;
    }
    //</editor-fold>
    private Resources resources;
    
    
    private TriGroup triGroupAstro1;
    
//    private SoundBuffer soundBufferChimes;
//    private SoundSource soundSourceChimes;
    
    public Level(Player player)
    {
        player.getViewPos().setStart(0.0f, 0.0f, 8.0f);
        player.getViewRot().setStart(0.0f, 0.0f);
        
        this.scene = new Scene3D();
        this.scene.setCameraTo(player.getCamera());
        
        this.resources = new Resources();
        this.resources.getLoaderTexture().loadTexture("sheet");
        this.resources.getLoaderModel().loadModelOBJ("astro1");
//        this.resources.getLoaderSound().loadSoundWAV("chimes");
        
        this.triGroupAstro1 = this.resources.getLoaderModel().getModelOBJ("astro1").getTriGroup();
        this.triGroupAstro1.setTexture(this.resources.getLoaderTexture().getTexture("sheet"));
        
//        this.soundBufferChimes = this.resources.getLoaderSound().getSoundWAV("chimes");
//        this.soundSourceChimes = new SoundSource(this.soundBufferChimes);
//        this.soundSourceChimes.setPosition(new vec3f(10.0f, 0.0f, 0.0f));
    }
    
    
    public void update(Player player)
    {
        this.scene.addGeometry(this.triGroupAstro1);
//        this.scene.addSoundSource(this.soundSourceChimes);
        this.scene.setSoundListenerPosition(player.getViewPos().getPos());
        this.scene.setSoundListenerDirection(player.getViewRot().getDir());
        this.scene.setSoundListenerVelocity(Vecmath.ORIGIN);
    }
    
    public void destroy()
    {
        this.triGroupAstro1.destroy();
//        this.soundSourceChimes.destroy();
//        this.soundBufferChimes.destroy();
        
        this.scene.destroy();
        this.resources.destroy();
    }
    
}
